package com.sh.data.engine.domain.taskalarm.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sh.data.engine.common.enumDefinition.TaskAlarmTypeEnum;
import com.sh.data.engine.common.exception.BusinessException;
import com.sh.data.engine.domain.base.model.PageResult;
import com.sh.data.engine.domain.base.model.UserContext;
import com.sh.data.engine.domain.dataasset.service.TblPropService;
import com.sh.data.engine.domain.datadev.flink.service.FlinkNodeService;
import com.sh.data.engine.domain.datadev.offline.model.param.OfflineDevTaskAlarmParam;
import com.sh.data.engine.domain.datadev.offline.service.DatadevMenuNodeService;
import com.sh.data.engine.domain.integration.api.http.model.domain.TaskDomain;
import com.sh.data.engine.domain.integration.api.http.service.ApiHttpService;
import com.sh.data.engine.domain.integration.api.webservice.service.ApiWsService;
import com.sh.data.engine.domain.integration.offline.service.OfflineSyncService;
import com.sh.data.engine.domain.integration.online.service.FlinkDataSyncService;
import com.sh.data.engine.domain.taskalarm.model.domain.DataIntegrationTaskDomain;
import com.sh.data.engine.domain.taskalarm.model.domain.TaskAlarmConfigDetailDomain;
import com.sh.data.engine.domain.taskalarm.model.domain.TaskAlarmConfigDetailDomain.DataIntegration;
import com.sh.data.engine.domain.taskalarm.model.domain.TaskAlarmConfigDetailDomain.DataQuality;
import com.sh.data.engine.domain.taskalarm.model.domain.TaskAlarmConfigDetailDomain.OfflineComputing;
import com.sh.data.engine.domain.taskalarm.model.domain.TaskAlarmConfigDetailDomain.RealTimeComputing;
import com.sh.data.engine.domain.taskalarm.model.domain.TaskAlarmConfigDomain;
import com.sh.data.engine.domain.taskalarm.model.param.TaskAlarmConfigParam;
import com.sh.data.engine.domain.taskalarm.service.*;
import com.sh.data.engine.domain.util.ConvertUtil;
import com.sh.data.engine.domain.workspace.manager.model.domain.UserDomain;
import com.sh.data.engine.domain.workspace.manager.service.UserService;
import com.sh.data.engine.domain.workspace.manager.service.impl.MailNoticeService;
import com.sh.data.engine.repository.dao.dataasset.entity.TblPropEntity;
import com.sh.data.engine.repository.dao.datadev.entity.DatadevMenuNodeEntity;
import com.sh.data.engine.repository.dao.datadev.entity.FlinkMenuNodeEntity;
import com.sh.data.engine.repository.dao.integration.offline.entity.OfflineSyncEntity;
import com.sh.data.engine.repository.dao.taskalarm.TaskAlarmConfigMapper;
import com.sh.data.engine.repository.dao.taskalarm.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author tinglan.ys
 * @description:
 * @date 2022/3/30 下午4:45
 */
@Service
@Slf4j
public class TaskAlarmServiceImpl extends ServiceImpl<TaskAlarmConfigMapper, TaskAlarmConfigEntity>
    implements TaskAlarmService {

    @Autowired
    private MailNoticeService mailNoticeService;

    @Autowired
    private UserService userService;

    @Autowired
    private OfflineSyncService offlineSyncService;

    @Autowired
    private TblPropService tblPropService;

    @Autowired
    private DatadevMenuNodeService datadevMenuNodeService;

    @Autowired
    private FlinkNodeService flinkNodeService;

    @Autowired
    private FlinkDataSyncService flinkDataSyncService;

    @Autowired
    private ApiHttpService apiHttpService;

    @Autowired
    private ApiWsService apiWsService;

    @Autowired
    private TaskAlarmDataSyncService taskAlarmDataSyncService;

    @Autowired
    private TaskAlarmRealTimeService taskAlarmRealTimeService;

    @Autowired
    private TaskAlarmDataqualityService taskAlarmDataqualityService;

    @Autowired
    private TaskAlarmFlowService taskAlarmFlowService;

    @Override
    public Boolean saveAlarmConfig(TaskAlarmConfigParam taskAlarmConfigParam) {
        TaskAlarmConfigEntity taskAlarmConfigEntity =
            ConvertUtil.copyProperties(taskAlarmConfigParam, TaskAlarmConfigEntity.class);
        String userId = UserContext.getUserId();
        String CreatorName = userService.getUserById(userId).getUserName();
        String receiverName =
            userService.getUserById(taskAlarmConfigParam.getReceiverId()).getUserName();
        Integer subjectType = taskAlarmConfigParam.getSubjectType();
        Long id = taskAlarmConfigParam.getId();
        if (Objects.nonNull(subjectType)) {
            if (subjectType.equals(0)) {
                TaskAlarmConfigDomain.OfflineComputing offlineComputing =
                    taskAlarmConfigParam.getOfflineComputing();
                LambdaQueryWrapper<TaskAlarmFlowEntity> eq =
                    new LambdaQueryWrapper<TaskAlarmFlowEntity>()
                        .eq(
                            Objects.nonNull(offlineComputing),
                            TaskAlarmFlowEntity::getNodeId,
                            offlineComputing.getNodeId())
                        .ne(Objects.nonNull(id), TaskAlarmFlowEntity::getAlarmId, id);
                long count = taskAlarmFlowService.count(eq);
                if (count > 0) {
                    throw new BusinessException("该对象的告警配置已经存在");
                }

            } else if (subjectType.equals(1)) {
                TaskAlarmConfigDomain.RealTimeComputing realTimeComputing =
                    taskAlarmConfigParam.getRealTimeComputing();
                LambdaQueryWrapper<TaskAlarmRealTimeEntity> eq =
                    new LambdaQueryWrapper<TaskAlarmRealTimeEntity>()
                        .eq(
                            Objects.nonNull(realTimeComputing),
                            TaskAlarmRealTimeEntity::getRealTimeId,
                            realTimeComputing.getId())
                        .ne(Objects.nonNull(id), TaskAlarmRealTimeEntity::getAlarmId, id);
                long count = taskAlarmRealTimeService.count(eq);
                if (count > 0) {
                    throw new BusinessException("该对象的告警配置已经存在");
                }
            } else if (subjectType.equals(2)) {
                TaskAlarmConfigDomain.DataQuality dataQuality = taskAlarmConfigParam.getDataQuality();
                LambdaQueryWrapper<TaskAlarmDataqualityEntity> eq =
                    new LambdaQueryWrapper<TaskAlarmDataqualityEntity>()
                        .eq(
                            Objects.nonNull(dataQuality),
                            TaskAlarmDataqualityEntity::getTblId,
                            dataQuality.getSjzlTblId())
                        .ne(Objects.nonNull(id), TaskAlarmDataqualityEntity::getAlarmId, id);
                long count = taskAlarmDataqualityService.count(eq);
                if (count > 0) {
                    throw new BusinessException("该对象的告警配置已经存在");
                }

            } else if (subjectType.equals(3)) {
                TaskAlarmConfigDomain.DataIntegration dataIntegration =
                    taskAlarmConfigParam.getDataIntegration();
                LambdaQueryWrapper<TaskAlarmDataSyncEntity> eq =
                    new LambdaQueryWrapper<TaskAlarmDataSyncEntity>()
                        .eq(
                            Objects.nonNull(dataIntegration),
                            TaskAlarmDataSyncEntity::getTaskId,
                            dataIntegration.getTaskId())
                        .ne(Objects.nonNull(id), TaskAlarmDataSyncEntity::getAlarmId, id);
                long count = taskAlarmDataSyncService.count(eq);
                if (count > 0) {
                    throw new BusinessException("该对象的告警配置已经存在");
                }
            }
        }
        // 保存逻辑
        taskAlarmConfigEntity.setUpdaterId(userId);
        taskAlarmConfigEntity.setCreatorId(userId);
        taskAlarmConfigEntity.setCreatorName(CreatorName);
        taskAlarmConfigEntity.setReceiverName(receiverName);
        saveOrUpdate(taskAlarmConfigEntity);

        if (taskAlarmConfigEntity.getSubjectType().equals(0)) {
            LambdaQueryWrapper<TaskAlarmFlowEntity> eq =
                new LambdaQueryWrapper<TaskAlarmFlowEntity>().eq(TaskAlarmFlowEntity::getAlarmId, id);
            taskAlarmFlowService.remove(eq);
            TaskAlarmFlowEntity taskAlarmFlowEntity =
                Convert.convert(TaskAlarmFlowEntity.class, taskAlarmConfigParam);
            taskAlarmFlowEntity.setAlarmId(taskAlarmConfigEntity.getId());
            taskAlarmFlowEntity.setNodeId(taskAlarmConfigParam.getOfflineComputing().getNodeId());
            taskAlarmFlowEntity.setIsInterrupt(
                taskAlarmConfigParam.getOfflineComputing().getIsInterrupt());
            taskAlarmFlowEntity.setTimeout(taskAlarmConfigParam.getOfflineComputing().getTimeout());
            taskAlarmFlowEntity.setThreshold(taskAlarmConfigParam.getOfflineComputing().getThreshold());
            taskAlarmFlowEntity.setUnFinishedTime(
                taskAlarmConfigParam.getOfflineComputing().getUnFinishedTime());
            DatadevMenuNodeEntity byId =
                datadevMenuNodeService.getById(taskAlarmConfigParam.getOfflineComputing().getNodeId());
            if (Objects.nonNull(byId)) {
                taskAlarmFlowEntity.setNodeName(byId.getName());
            }
            taskAlarmFlowService.save(taskAlarmFlowEntity);
        } else if (taskAlarmConfigEntity.getSubjectType().equals(1)) {
            LambdaQueryWrapper<TaskAlarmRealTimeEntity> eq =
                new LambdaQueryWrapper<TaskAlarmRealTimeEntity>()
                    .eq(TaskAlarmRealTimeEntity::getAlarmId, id);
            taskAlarmRealTimeService.remove(eq);
            TaskAlarmRealTimeEntity taskAlarmRealTimeEntity =
                Convert.convert(TaskAlarmRealTimeEntity.class, taskAlarmConfigParam);
            taskAlarmRealTimeEntity.setAlarmId(taskAlarmConfigEntity.getId());
            Long id1 = taskAlarmConfigParam.getRealTimeComputing().getId();
            taskAlarmRealTimeEntity.setRealTimeId(id1);
            FlinkMenuNodeEntity byId = flinkNodeService.getById(id1);
            if (Objects.nonNull(byId)) {
                taskAlarmRealTimeEntity.setName(byId.getName());
            }
            taskAlarmRealTimeService.save(taskAlarmRealTimeEntity);
        } else if (taskAlarmConfigEntity.getSubjectType().equals(2)) {
            LambdaQueryWrapper<TaskAlarmDataqualityEntity> eq =
                new LambdaQueryWrapper<TaskAlarmDataqualityEntity>()
                    .eq(TaskAlarmDataqualityEntity::getAlarmId, id);
            taskAlarmDataqualityService.remove(eq);
            TaskAlarmDataqualityEntity taskAlarmDataqualityEntity =
                Convert.convert(TaskAlarmDataqualityEntity.class, taskAlarmConfigParam);
            taskAlarmDataqualityEntity.setAlarmId(taskAlarmConfigEntity.getId());
            taskAlarmDataqualityEntity.setTblId(taskAlarmConfigParam.getDataQuality().getSjzlTblId());
            taskAlarmDataqualityService.save(taskAlarmDataqualityEntity);
        } else {
            LambdaQueryWrapper<TaskAlarmDataSyncEntity> eq =
                new LambdaQueryWrapper<TaskAlarmDataSyncEntity>()
                    .eq(TaskAlarmDataSyncEntity::getAlarmId, id);
            taskAlarmDataSyncService.remove(eq);
            TaskAlarmDataSyncEntity taskAlarmFlowEntity =
                Convert.convert(TaskAlarmDataSyncEntity.class, taskAlarmConfigParam);
            taskAlarmFlowEntity.setAlarmId(taskAlarmConfigEntity.getId());
            taskAlarmFlowEntity.setTaskId(taskAlarmConfigParam.getDataIntegration().getTaskId());
            taskAlarmFlowEntity.setSyncType(taskAlarmConfigParam.getDataIntegration().getSyncType());
            taskAlarmFlowEntity.setFailedNum(taskAlarmConfigParam.getDataIntegration().getFailedNum());
            taskAlarmDataSyncService.save(taskAlarmFlowEntity);
        }
        return true;
    }

    private void searchAndRemove(Integer subjectType, Long id) {
        if (subjectType.equals(0)) {
            LambdaQueryWrapper<TaskAlarmFlowEntity> eq =
                new LambdaQueryWrapper<TaskAlarmFlowEntity>().eq(TaskAlarmFlowEntity::getAlarmId, id);
            taskAlarmFlowService.remove(eq);
        } else if (subjectType.equals(1)) {
            LambdaQueryWrapper<TaskAlarmRealTimeEntity> eq =
                new LambdaQueryWrapper<TaskAlarmRealTimeEntity>()
                    .eq(TaskAlarmRealTimeEntity::getAlarmId, id);
            taskAlarmRealTimeService.remove(eq);
        } else if (subjectType.equals(2)) {
            LambdaQueryWrapper<TaskAlarmDataqualityEntity> eq =
                new LambdaQueryWrapper<TaskAlarmDataqualityEntity>()
                    .eq(TaskAlarmDataqualityEntity::getAlarmId, id);
            taskAlarmDataqualityService.remove(eq);
        } else {
            LambdaQueryWrapper<TaskAlarmDataSyncEntity> eq =
                new LambdaQueryWrapper<TaskAlarmDataSyncEntity>()
                    .eq(TaskAlarmDataSyncEntity::getAlarmId, id);
            taskAlarmDataSyncService.remove(eq);
        }
    }

    @Override
    public List<UserDomain> getReceiver() {
        List<UserDomain> receiver = mailNoticeService.getReceiver();
        return receiver;
    }

    @Override
    public Boolean del(Long id) {
        TaskAlarmConfigEntity byId1 = getById(id);
        searchAndRemove(byId1.getSubjectType(), id);
        removeById(id);
        return true;
    }

    @Override
    public PageResult<TaskAlarmConfigDomain> getList(
        Integer subjectType,
        Integer receiveType,
        Integer alarmType,
        String receiverName,
        String creatorName,
        Integer pageNum,
        Integer pageSize,
        Long projectId) {

        LambdaQueryWrapper<TaskAlarmConfigEntity> eq =
            new LambdaQueryWrapper<TaskAlarmConfigEntity>()
                .eq(TaskAlarmConfigEntity::getProjectId, projectId);
        eq.orderByDesc(TaskAlarmConfigEntity::getCreateTime);

        if (subjectType != null) {
            eq.eq(TaskAlarmConfigEntity::getSubjectType, subjectType);
        }
        if (receiveType != null) {
            eq.eq(TaskAlarmConfigEntity::getReceiveType, receiveType);
        }
        if (alarmType != null) {
            eq.eq(TaskAlarmConfigEntity::getAlarmType, alarmType);
        }
        if (receiverName != null) {
            eq.and(
                e ->
                    e.like(TaskAlarmConfigEntity::getReceiverName, receiverName));
        }

        List<TaskAlarmConfigEntity> taskAlarmConfigEntities = list(eq);

        List<TaskAlarmConfigDomain> taskAlarmConfigDomains = new ArrayList<>();

        for (TaskAlarmConfigEntity taskAlarmConfigEntity : taskAlarmConfigEntities) {
            // 根据不同的监控主题 封装返回值
            TaskAlarmConfigDomain taskAlarmConfigDomain = new TaskAlarmConfigDomain();
            // 监控主题 0-离线计算 1-实时计算 2-数据质量 3-数据集成
            if (taskAlarmConfigEntity.getSubjectType() == 0) {
                // 监控主题
                taskAlarmConfigDomain.setSubjectType(0);
                // 告警对象 离线计算nodeId
                TaskAlarmFlowEntity one =
                    taskAlarmFlowService.getOne(
                        new LambdaQueryWrapper<TaskAlarmFlowEntity>()
                            .eq(TaskAlarmFlowEntity::getAlarmId, taskAlarmConfigEntity.getId()));
                DatadevMenuNodeEntity menuNodeEntity = datadevMenuNodeService.getById(one.getNodeId());
                taskAlarmConfigDomain.setTaskObject(menuNodeEntity.getName());
                // 告警原因
                taskAlarmConfigDomain.setAlarmType(taskAlarmConfigEntity.getAlarmType());
                taskAlarmConfigDomain.setAlarmTypeName(
                    TaskAlarmTypeEnum.getNameByCode(taskAlarmConfigEntity.getAlarmType()));
                // 通知方式
                taskAlarmConfigDomain.setReceiveType(taskAlarmConfigEntity.getReceiveType());
                // 通知人
                taskAlarmConfigDomain.setReceiverName(taskAlarmConfigEntity.getReceiverName());
                // 创建人
                taskAlarmConfigDomain.setCreatorName(taskAlarmConfigEntity.getCreatorName());
                // 通知人邮件地址
                taskAlarmConfigDomain.setReceiverEmail(
                    userService.getUserById(taskAlarmConfigEntity.getReceiverId()).getEmail());
                // id
                taskAlarmConfigDomain.setId(taskAlarmConfigEntity.getId());
                taskAlarmConfigDomains.add(taskAlarmConfigDomain);

            } else if (taskAlarmConfigEntity.getSubjectType() == 1) {
                // 监控主题
                taskAlarmConfigDomain.setSubjectType(1);
                // 告警对象
                TaskAlarmRealTimeEntity one =
                    taskAlarmRealTimeService.getOne(
                        new LambdaQueryWrapper<TaskAlarmRealTimeEntity>()
                            .eq(TaskAlarmRealTimeEntity::getAlarmId, taskAlarmConfigEntity.getId()));

                taskAlarmConfigDomain.setTaskObject(one.getName());
                // 告警原因
                taskAlarmConfigDomain.setAlarmType(taskAlarmConfigEntity.getAlarmType());
                taskAlarmConfigDomain.setAlarmTypeName(
                    TaskAlarmTypeEnum.getNameByCode(taskAlarmConfigEntity.getAlarmType()));
                // 通知方式
                taskAlarmConfigDomain.setReceiveType(taskAlarmConfigEntity.getReceiveType());
                // 通知人
                taskAlarmConfigDomain.setReceiverName(taskAlarmConfigEntity.getReceiverName());
                // 创建人
                taskAlarmConfigDomain.setCreatorName(taskAlarmConfigEntity.getCreatorName());
                // 通知人邮件地址
                taskAlarmConfigDomain.setReceiverEmail(
                    userService.getUserById(taskAlarmConfigEntity.getReceiverId()).getEmail());
                // id
                taskAlarmConfigDomain.setId(taskAlarmConfigEntity.getId());
                taskAlarmConfigDomains.add(taskAlarmConfigDomain);

            } else if (taskAlarmConfigEntity.getSubjectType() == 2) {
                // 监控主题
                taskAlarmConfigDomain.setSubjectType(2);
                // 告警对象
                TaskAlarmDataqualityEntity one =
                    taskAlarmDataqualityService.getOne(
                        new LambdaQueryWrapper<TaskAlarmDataqualityEntity>()
                            .eq(TaskAlarmDataqualityEntity::getAlarmId, taskAlarmConfigEntity.getId()));

                TblPropEntity tblPropByTblId = tblPropService.getTblPropByTblId(projectId, one.getTblId());
                if (tblPropByTblId != null) {
                    if (StringUtils.isNotBlank(tblPropByTblId.getSchema())) {
                        taskAlarmConfigDomain.setTaskObject(
                            tblPropByTblId.getSchema() + "." + tblPropByTblId.getTableName());
                    } else {
                        taskAlarmConfigDomain.setTaskObject(tblPropByTblId.getTableName());
                    }
                }
                // 告警原因
                taskAlarmConfigDomain.setAlarmType(taskAlarmConfigEntity.getAlarmType());
                taskAlarmConfigDomain.setAlarmTypeName(
                    TaskAlarmTypeEnum.getNameByCode(taskAlarmConfigEntity.getAlarmType()));
                // 通知方式
                taskAlarmConfigDomain.setReceiveType(taskAlarmConfigEntity.getReceiveType());
                // 通知人
                taskAlarmConfigDomain.setReceiverName(taskAlarmConfigEntity.getReceiverName());
                // 创建人
                taskAlarmConfigDomain.setCreatorName(taskAlarmConfigEntity.getCreatorName());
                // 通知人邮件地址
                taskAlarmConfigDomain.setReceiverEmail(
                    userService.getUserDetailByIdWithoutRole(taskAlarmConfigEntity.getReceiverId()).getEmail());
                // id
                taskAlarmConfigDomain.setId(taskAlarmConfigEntity.getId());
                taskAlarmConfigDomains.add(taskAlarmConfigDomain);

            } else {
                // 监控主题
                taskAlarmConfigDomain.setSubjectType(3);
                // 告警对象

                TaskAlarmDataSyncEntity one =
                    taskAlarmDataSyncService.getOne(
                        new LambdaQueryWrapper<TaskAlarmDataSyncEntity>()
                            .eq(TaskAlarmDataSyncEntity::getAlarmId, taskAlarmConfigEntity.getId()));
                if (one.getSyncType().equals(0)) {
                    OfflineSyncEntity byId = offlineSyncService.getById(one.getTaskId());
                    if (null == byId) {
                        continue;
                    }
                    taskAlarmConfigDomain.setTaskObject(byId.getTaskName());
                } else if (one.getSyncType().equals(1)) {
                    // todo flik data sync

                } else if (one.getSyncType().equals(2)) {
                    TaskDomain taskById = apiHttpService.getTaskById(one.getTaskId());
                    if (null == taskById) {
                        continue;
                    }
                    taskAlarmConfigDomain.setTaskObject(taskById.getTaskName());
                } else if (one.getSyncType().equals(3)) {
                    com.sh.data.engine.domain.integration.api.webservice.model.domain.TaskDomain taskById =
                        apiWsService.getTaskById(one.getTaskId());
                    if (null == taskById) {
                        continue;
                    }
                    taskAlarmConfigDomain.setTaskObject(taskById.getTaskName());
                }
                // 告警原因
                taskAlarmConfigDomain.setAlarmType(taskAlarmConfigEntity.getAlarmType());
                taskAlarmConfigDomain.setAlarmTypeName(
                    TaskAlarmTypeEnum.getNameByCode(taskAlarmConfigEntity.getAlarmType()));
                // 通知方式
                taskAlarmConfigDomain.setReceiveType(taskAlarmConfigEntity.getReceiveType());
                // 通知人
                taskAlarmConfigDomain.setReceiverName(taskAlarmConfigEntity.getReceiverName());
                // 创建人
                taskAlarmConfigDomain.setCreatorName(taskAlarmConfigEntity.getCreatorName());
                // 通知人邮件地址
                taskAlarmConfigDomain.setReceiverEmail(
                    userService.getUserById(taskAlarmConfigEntity.getReceiverId()).getEmail());
                // id
                taskAlarmConfigDomain.setId(taskAlarmConfigEntity.getId());
                taskAlarmConfigDomains.add(taskAlarmConfigDomain);
            }
        }

        PageResult taskAlarmConfigParamPageResult =
            new PageResult(taskAlarmConfigDomains, pageNum, pageSize);

        return taskAlarmConfigParamPageResult;
    }

    @Override
    public boolean saveTaskFlowAlarmConfig(OfflineDevTaskAlarmParam offlineDevTaskAlarmParam) {
    /*TaskAlarmConfigEntity taskAlarmConfigEntity =
        ConvertUtil.copyProperties(offlineDevTaskAlarmParam, TaskAlarmConfigEntity.class);
    taskAlarmConfigEntity.setUpdateTime(new Date());
    if (StringUtils.isBlank(offlineDevTaskAlarmParam.getId())) {
      taskAlarmConfigEntity.setCreateTime(new Date());
      taskAlarmConfigMapper.insertOne(taskAlarmConfigEntity);
    } else {
      taskAlarmConfigMapper.updateByIdSelective(taskAlarmConfigEntity);
    }*/
        return true;
    }

    @Override
    public List<DataIntegrationTaskDomain> getTaskName(Integer taskType) {

        if (taskType == 0) {
            List<DataIntegrationTaskDomain> dataIntegrationTaskDomains = new ArrayList<>();
            //  0-离线同步
            for (OfflineSyncEntity offlineSyncEntity : offlineSyncService.list()) {
                DataIntegrationTaskDomain dataIntegrationTaskDomain = new DataIntegrationTaskDomain();
                dataIntegrationTaskDomain.setTaskId(String.valueOf(offlineSyncEntity.getId()));
                dataIntegrationTaskDomain.setTaskName(offlineSyncEntity.getTaskName());
                dataIntegrationTaskDomains.add(dataIntegrationTaskDomain);
            }
            return dataIntegrationTaskDomains;
        } else {
            // todo 1-实时同步

            return null;
        }
    }

    @Override
    public List<UserDomain> getReceiverFromUser() {
        List<UserDomain> all = userService.findAll();
        return all;
    }

    @Override
    public TaskAlarmConfigDetailDomain detail(Long id) {
        TaskAlarmConfigEntity byId = getById(id);
        TaskAlarmConfigDetailDomain taskAlarmConfigDetailDomain =
            Convert.convert(TaskAlarmConfigDetailDomain.class, byId);
        Integer subjectType = byId.getSubjectType();

        if (subjectType == 0) {
            TaskAlarmFlowEntity one =
                taskAlarmFlowService.getOne(
                    new LambdaQueryWrapper<TaskAlarmFlowEntity>()
                        .eq(TaskAlarmFlowEntity::getAlarmId, byId.getId()));
            OfflineComputing convert = Convert.convert(OfflineComputing.class, one);
            taskAlarmConfigDetailDomain.setOfflineComputing(convert);
        } else if (subjectType == 1) {
            TaskAlarmRealTimeEntity one =
                taskAlarmRealTimeService.getOne(
                    new LambdaQueryWrapper<TaskAlarmRealTimeEntity>()
                        .eq(TaskAlarmRealTimeEntity::getAlarmId, byId.getId()));
            RealTimeComputing convert = Convert.convert(RealTimeComputing.class, one);
            convert.setId(one.getRealTimeId());
            taskAlarmConfigDetailDomain.setRealTimeComputing(convert);
        } else if (subjectType == 2) {
            TaskAlarmDataqualityEntity one =
                taskAlarmDataqualityService.getOne(
                    new LambdaQueryWrapper<TaskAlarmDataqualityEntity>()
                        .eq(TaskAlarmDataqualityEntity::getAlarmId, byId.getId()));
            DataQuality dataQuality = new DataQuality();
            dataQuality.setSjzlTblId(one.getTblId());
            taskAlarmConfigDetailDomain.setDataQuality(dataQuality);
        } else if (subjectType == 3) {

            TaskAlarmDataSyncEntity one =
                taskAlarmDataSyncService.getOne(
                    new LambdaQueryWrapper<TaskAlarmDataSyncEntity>()
                        .eq(TaskAlarmDataSyncEntity::getAlarmId, byId.getId()));
            DataIntegration convert = Convert.convert(DataIntegration.class, one);
            taskAlarmConfigDetailDomain.setDataIntegration(convert);
        }
        return taskAlarmConfigDetailDomain;
    }
}
